package com.inspur.edp.common.expr.expresses.method;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.inspur.edp.common.expr.ExprJsonDeserializer;
import com.inspur.edp.common.expr.Express;
import lombok.Data;

import java.util.List;

/**
 * @author lizhaorui
 * @description TODO
 * @date 2024/12/12 13:57
 */
@Data
public class MethodInvokeExpr implements Express {

    public static final String KIND = "methodInvoke";

    private boolean isStatic;

    /**
     * 是静态，typeUrl不为空
     */
    private String typeUrl;

    /**
     * 非静态，express不能为空
     */
    @JsonDeserialize(using = ExprJsonDeserializer.class)
    private Express express;

    private String methodCode;

    private List<MethodParameter> parameters;

    @JsonIgnore
    public void addParameter(Express express) {
        MethodParameter parameter = new MethodParameter();
        parameter.setValue(express);
        this.parameters.add(parameter);
    }

    @Override
    public String getKind() {
        return KIND;
    }

    @Data
    public static class MethodParameter {

        private String code;

        @JsonDeserialize(using = ExprJsonDeserializer.class)
        private Express value;
    }
}
